<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
$this->load->view ( 'home/common/header' );
?>
<?php
	$user_Email=$this->session->userdata('sessionEmail');	
					 
?>
<script language="javascript"
	src="<?php
	echo base_url ();
	?>themes/default/javascript/jquery.tools.min.js"
	type="text/javascript"></script>

<link rel="stylesheet" type="text/css" media="screen"
	href="<?php
	echo base_url ();
	?>themes/default/css/style_tabs.css" />
<link rel="stylesheet" type="text/css" media="screen"
	href="<?php
	echo base_url ();
	?>themes/default/css/tabs-panes.css" />

<!--body start -->
<div id="ja-content-main" class="ja-content-main clearfix" style="padding: 0px 13px 19px 18px;">                               
<div class="item-page"></div>
		<!-- -----------------Bat dau Tab------------------------ --->
			<div class="profileHeader">
				<div class="fl profileHeaderTitle">Trang quản lý cá nhân</div>
				<div class="fr">
					<a class="profileAddGold" href="javascript:void(0)"
						onclick="shop.gold.rechargeStep1();"
						title="Nạp tiền vào Ví MuaChung">Nạp tiền</a>
				</div>
				<div class="c"></div>
			</div>
			<div class="profileTab">
				<ul class="reportType">
					<li class="fl"><a id='common' class="fixPNG active" href="javascript:void(0)">Sửa thông tin chung</a></li>
					<li class="fl"><a id='expand' class="fixPNG" href="javascript:void(0)">Sửa thông tin mở rộng</a></li>
					<li class="fl"><a id='manaplace' class="fixPNG" href="javascript:void(0)">Quản lý đăng tin</a></li>
					
				</ul>
				<div class="c"></div>
			</div>
	

			<!-- ----------------------------------Tab 1 Register form common----------------------------->
			<div id='commonInfo' style="display:">
			<form enctype="multipart/form-data" method="post" id="editForm" name="editForm">
				<input type="hidden" value="<?php echo $user_Email;?>" name="email"/>
				<div class="profileContainer">
						<div style="height: 400px; padding-top: 20px;">

							<table width="100%">
								<tr>
									<td align="left" width="150px"><label
										style="float: left; width: 150px" for="email_edit">Email:</label></td>
									<td><input value="<?php echo $user_Email;?>"
										style="float: left; background: #FFF37B;" type="text"
										name="email_edit" id="email_edit" disabled=""
										class="text ui-widget-content ui-corner-all pd5 txt"
										maxlength="200" size="25" /> <span
										style="color: red; float: left; width: auto;">*</span></td>
								</tr>
								<tr>

									<td align="left" width="150px"></td>
									<td align="left"><input name='changePass' id='changePass' type="checkbox"
										title='Bật tính năng đổi mật khẩu' /><span
										style='color: #0076B2'>&nbsp;&nbsp;&nbsp;&nbsp;Đổi mật khẩu</span></input>
									</td>
								</tr>

								<tr id='Iform' style="display: none">
									<td align="left"><label for="password_edit">Mật khẩu cũ:</label></td>
									<td align="left"><input type="password" name="password_edit"
										style='' id="password_edit"
										class="text ui-widget-content ui-corner-all pd5"
										maxlength="30" size="25" /></td>
								</tr>
								<tr id='Iform' style="display: none">
									<td align="left"><label for="passwordNew_edit">Mật khẩu mới:</label></td>
									<td align="left"><input type="password" name="passwordNew_edit"
										style='' id="passwordNew_edit"
										class="text ui-widget-content ui-corner-all pd5"
										maxlength="30" size="25" /></td>
								</tr>
								<tr id='Iform' style="display: none">
									<td align="left" width="120px"><label
										style="float: left; width: 150px" for="confirmPassword_edit">Nhập
											lại mật khẩu:</label></td>
									<td><input style="float: left;" type="password"
										name="confirmPassword_edit" id="confirmPassword_edit"
										class="text ui-widget-content ui-corner-all pd5"
										maxlength="30" size="25" /> <span class='yeucau'>*</span></td>
								</tr>

								<tr>
									<td align="left"><label for="fullName_edit">Họ tên:</label></td>
									<td align="left"><input style="float: left;" type="text"
										name="fullName_edit" id="fullName_edit"
										class="text ui-widget-content ui-corner-all pd5 txt"
										maxlength="200" size="25" /> <span class='yeucau'>*</span>
								
								</tr>
								<tr>
									<td align="left"><label for="mobil_edit">Điện thoại di động:</label></td>
									<td align="left"><input style="float: left;" type="text"
										name="mobil_edit" id="mobil_edit"
										class="text ui-widget-content ui-corner-all pd5"
										maxlength="200" size="25" /> <span class='yeucau'>*</span>
								
								</tr>
								<tr>
									<td align="left" valign="top"><label for="captcha_edit">Mã xác
											thực:</label></td>
									<td align="left" valign="top">
										<div class='fl'>
											<img
												src='<?php echo base_url(); ?>themes/home/images/noCode.jpg'
												id='captcha'
												style="border: 1px solid #aaaaaa;float:left; width:85px; height:30px;" />
											<img style="margin-left: 10px; cursor: pointer; float:left"
												alt="Tạo mã khác" title="Tạo mã khác"
												src="<?php echo base_url(); ?>themes/default/images/refresh.png"
												onclick="javascript:getCaptCha();" id="reload_button"/><input
												type="text" size="5" maxlength="5" id='captcha_edit'
												name='captcha_edit'
												style="color: red;; margin-left: 5px;"
												class="text ui-widget-content ui-corner-all pd5 fl"/>
										
										</div>
									</td>
								</tr>
								<tr>
									<td align="left"><label></label></td>
									<td class="fl" style="margin-left: 90px;"><a
										onclick="doCommon();" href="javascript:void(0)"
										class="profileAddGold">Cập nhật</a> <input type="hidden"
										value="444703" id="user_id"/></td>
								</tr>
							</table>

						</div>

						
				</div>
			</form>
		</div>
		<!-- ----------------------------------End register form common ------------------------------------------------------------------------->
		
		<!-- ----------------------------------Tab2 Start register form expand ------------------------------------------------------------------------->
		<div id='expandInfo' style="display:none">
			<form enctype="multipart/form-data" method="post" id="editFormExpand" name="editFormExpand">
				<input type="hidden" value="<?php echo $user_Email;?>" name="email"/>
				<div class="profileContainer">
						<div style="height: 400px; padding-top: 20px;">
							<table width="100%" height="250px">

											<tr>
												<td align="left" valign="top" width="150px"><label
													style="width: 150px" for="gender_edit" >Giới tính:</label></td>
												<td><select name="gender_edit" id="gender_edit" class="ui-corner-all pd5"
													style="width: 70px;">
														<option value="0">Nam</option>
														<option value="1">Nữ</option>
												</select> <span class='yeucau'>*</span></td>
											</tr>
											<tr>
												<td align="left" valign="top"><label for="address_edit">Địa
														chỉ:</label></td>
												<td align="left" valign="top"><input type="text"
													name="address_edit" id="address_edit" style="float: left;"
													class="text ui-widget-content ui-corner-all pd5 txt" maxlength="200" size="25"
													 /> <span
													style="color: red; float: left; width: auto;">*</span></td>
											</tr>

											<tr>
												<td align="left" valign="top" width="120px"><label
													style="float: left; width: 120px" for="city_edit">Tỉnh/Thành
														phố:</label></td>
												<td><select type="text" name="city_edit" id="city_edit"
													style="float: left; width:15em;" class="text ui-widget-content ui-corner-all pd5 txt"> 
													</select>
													<span style="color: red; float: left; width: auto;">*</span>
											    </td>
											</tr>

											<tr>
												<td align="left" valign="top"><label for="sky_edit">Nick
														skype:</label></td>
												<td align="left" valign="top"><input type="text" size="25px" maxlength="100px"
													style=" float: left;" id='sky_edit'
													name='sky_edit'
													class="text ui-widget-content ui-corner-all pd5 txt"/> <font
													color="#FF0000" style='float: left;'>*</font></td>
											</tr>
											<tr>
												<td align="left" valign="top"><label for="yahoo_edit">Nick
														Yahoo:</label></td>
												<td align="left" valign="top"><input type="text" size="25px" maxlength="100px"
													style='float: left;' name="yahoo_edit"
													id="yahoo_edit"
													class="text ui-widget-content ui-corner-all pd5 txt"/><font
													color="#FF0000" style='float: left;'>*</font></td>
											</tr>
											<tr>
											<td align="left"><label></label></td>
											<td class="fl" style="margin-left: 90px;"><a
												onclick="doExpand();" href="javascript:void(0)"
												class="profileAddGold">Cập nhật</a> <input type="hidden"
												value="444703" id="user_id"/></td>
										     </tr>
										</table>

						</div>

						
				</div>
			</form>
		
		</div>
		
		<!-- ----------------------------------Endregister form expand ------------------------------------------------------------------------->
		
		<!-- ----------------------------------Tab3 ------------------------------------------------------------------------->
		<br></br>
		<div id='manaInfo' style="display:'none'">
			<table id="showGrid"></table>
		    <div id="pager1"></div> 
		
		</div>
		
		<!-- ----------------------------------End Tab3 ------------------------------------------------------------------------->
		
<script>
jQuery("#showGrid").jqGrid({
   	url:'<?php echo base_url(); ?>user/getAll',
   	viewrecords: true,
	multiselect: true,
	mtype: "POST", 
	postData:{act:'viewAll'},
   	datatype: "json",
   	colNames:["Id",
	   		  "Tiêu đề", 
	   		  "Nội dung",
	   	      "Ngày đăng",
	   	      "Giá",
	   	      "kiểu"
	   	     ],
   	colModel:[
   		{name:'id',index:'id', width:40},
   		{name:'title',index:'title', width:90},
   		{name:'content',index:'description', width:0,hidden:true},
   		{name:'datePost',index:'createddate', width:60 },
   		{name:'price',index:'price', width:80,align:'right' },
   		{name:'type',index:'housetype', width:50 }
   	],
   	rowNum:30,
    width: 730,
    height: 'auto',
   	rowList:[30,50,100,150,200,300],
   	pager: jQuery('#pager1'),
   	sortname: 'id',
    viewrecords: true,
    sortorder: "desc",
    caption:"Danh sách các thành viên",
    gridComplete: function()
	{ 
		var ids = jQuery("#showGrid").jqGrid('getDataIDs'); 
	       for(var i=0;i < ids.length;i++)
	       { 
	        	var cl = ids[i];
	        	var ret = jQuery("#showGrid").jqGrid('getRowData',cl);
	        	var status=ret.status;
	        	if(status=='1')
	        	{
	        		status="<a href='#'><img src='<?php echo base_url(); ?>themes/admin/images/active.png'/></a>";
	        	}else
	        	{
	        		status="<a href='#'><img src='<?php echo base_url(); ?>themes/admin/images/deactive.png'href='#'/></a>";
	        	}
	        	jQuery("#showGrid").jqGrid('setRowData',ids[i],{status:status});
	        } 
	    }
	
}).navGrid('#pager1',{edit:false,add:false,del:false});


var city_id='';
jQuery().ready(function ()
		  {
		 /*---------------------------Start Get province----------------------------*/
		 	jQuery.ajax
		     ({
		         type: "POST",
		         url: '<?php echo base_url(); ?>province/getProvinceList',
		         dataType: 'json',
		         async: false,
		         data: {q:'all'}
		        ,success:function(msg)
		        {	 
		        } 
		     }).done(function( msg ) 
		     {
		 		//Fill Data into combobox:
		     	var city_edit = jQuery('#city_edit');
		 		city_edit.find('option').remove().end();
		 		jQuery.each(msg.rows, function(index, itemData) 
		 		{
		 	       city_edit.append("<option rel='"+itemData.id+"' value='"+itemData.id+"'>"+itemData.name+"</option>");   
		 		});	
		 		
		 		city_edit.val(city_id);			
		     });
		  });
getUser();
	/*---------------------------End Get province----------------------------*/	
jQuery().ready(function ()
{
	 getCaptCha();
	 jQuery('#changePass').change(function() 
		{
		
		  jQuery("#confirmPassword_edit").val('');
		  jQuery("#password_edit").val('');
		  jQuery("#passwordNew_edit").val('');
		 
		  if(jQuery('#changePass').is(':checked')==true)//checked
		  {
			 jQuery("table").find('#Iform').each(function () 
			  {
				jQuery(this).css('display','');
		      });
		 }else
		 {
			 jQuery("table").find('#Iform').each(function () 
			{
			  jQuery(this).css('display','none');
			});
		}
	});
});
/*--------------------Start get user---------------------------*/

function getUser()
{
	var method={act:'getOne',session:'true',key:randomString()};
	var myJSONtext=jQuery('#editForm').toJSON();

	var output = {};
	output = jsonConcat(output, myJSONtext);
	output = jsonConcat(output, method);
	
	jQuery.ajax({
		url: '<?php echo base_url(); ?>user/getOne',
		dataType: "json",
		data:output,
		type: "POST",
		async: true,
		success: function(msg) 
		{
			//Fill Data into combobox:
			jQuery.each(msg.rows, function(index, itemData) 
			{
				 jQuery('#fullName_edit').val(itemData.fullname);
				 jQuery('#mobil_edit').val(itemData.mobil);
				 jQuery('#gender_edit').val(itemData.gender);
				 jQuery('#sky_edit').val(itemData.skype);
				 jQuery('#yahoo_edit').val(itemData.yahoo);
				 jQuery('#address_edit').val(itemData.addr);
				 jQuery('#city_edit').val(itemData.province);
				 jQuery("#confirmPassword_edit").val('');
				 jQuery("#password_edit").val('');
				 jQuery("#passwordNew_edit").val('');
				 city_id=itemData.province;
		      
			});	
		}
	});
}
/*--------------------End get user-----------------------------------*/
/*---------------------check data valid -----------------------------*/

function check_Data()
{
	//checkAdsession();
	 //Check email
	if(!jQuery.checkEmail(jQuery("#email_edit").val()))
    {
    	 jQuery("#email_edit").focus();
    	 jQuery.showErr(" Địa chỉ email không hợp lệ!");
    	  addToBasket('bee','email_edit');
    	 return false;
    }
	//Check email is exites
	
	//Yeu cau doi mat khau
	if(jQuery('#changePass').is(':checked')==true)//checked
	{
		//Check pass:
	    if(jQuery("#password_edit").val()=='')
	    {
	    	 jQuery("#password_edit").focus();
	    	 jQuery.showErr(" Xin vui lòng nhập mật khẩu cũ!");
	    	 addToBasket('bee','password_edit');
	    	 return false;
	    }
	    //Check pass:
	    if(jQuery("#passwordNew_edit").val()=='')
	    {
	    	 jQuery("#passwordNew_edit").focus();
	    	 jQuery.showErr(" Xin vui lòng nhập mật khẩu mới!");
	    	 addToBasket('bee','passwordNew_edit');
	    	 return false;
	    }
	     //check confirm pass
		if(jQuery('#confirmPassword_edit').val()!=jQuery("#passwordNew_edit").val())
		{
			jQuery("#confirmPassword_edit").focus();
	     	jQuery.showErr("Xác nhận mật khẩu không đúng!");
	     	 addToBasket('bee','confirmPassword_edit');
	    	return false;
		}
	}
	//Check fullName:
    if(jQuery("#fullName_edit").val()=='')
    {
    	 jQuery("#fullName_edit").focus();
    	 jQuery.showErr(" Xin vui lòng nhập Họ và tên!");
    	 addToBasket('bee','fullName_edit');
    	 return false;
    }
	//Check mobil:
    if(jQuery("#mobil_edit").val()=='')
    {
    	 jQuery("#mobil_edit").focus();
    	 jQuery.showErr(" Xin vui lòng nhập số điện thoại di động!");
    	 addToBasket('bee','mobil_edit');
    	 return false;
    }
	  //Check Captcha:
    if(jQuery("#captcha_edit").val()=='')
    {
    	 jQuery("#captcha_edit").focus();
    	 jQuery.showErr(" Xin vui lòng nhập mã xác thực hình trên!");
    	 addToBasket('bee','captcha_edit');
    	 return false;
    }
    
	return true;
}

/*---------------------check data valid -----------------------------*/

/*---------------------Start Submit----------------------------------*/
//Common
function doCommon()
{
	if(!check_Data())return true;
	var method={act:'commonEdit',session:'true',key:randomString()};
	var myJSONtext=jQuery('#editForm').toJSON();
	var output = {};
	output = jsonConcat(output, myJSONtext);
	output = jsonConcat(output, method);
	jQuery.ajax({
		url: '<?php echo base_url(); ?>user/process',
		dataType: "json",
		data:output,
		type: "POST",
		async: true,
		success: function(msg) 
		{
			if(msg.ret=='invalid')
			{
				jQuery("#password_edit").focus();
		    	 jQuery.showErr(" Mật khẩu cũ không chính xác, Xin vui lòng nhập lại mật khẩu cũ!");
		    	 addToBasket('bee','password_edit');
		    	 return false;
			}else if(msg.ret=='success')
			{
				alert('Thay đổi thông tin thành công!');
				getUser();
				if(jQuery('#changePass').is(':checked')==true)//checked
				{
					jQuery('#changePass').click();
				}
			}else if(msg.ret=='noCaptcha')
			{
				jQuery("#captcha_edit").focus();
		    	jQuery.showErr("Nhập thông tin mã xác thực không đúng!");
		    	addToBasket('bee','captcha_edit');
		    	return false;
			}
			getCaptCha();
		}
	});
}
//Expand
function doExpand()
{
	var method={act:'expandEdit',session:'true',key:randomString()};
	var myJSONtext=jQuery('#editFormExpand').toJSON();
	var output = {};
	output = jsonConcat(output, myJSONtext);
	output = jsonConcat(output, method);
	jQuery.ajax({
		url: '<?php echo base_url(); ?>user/process',
		dataType: "json",
		data:output,
		type: "POST",
		async: true,
		success: function(msg) 
		{
			if(msg.ret=='success')
			{
				alert('Thay đổi thông tin thành công!');
				getUser();
			}
			
		}
	});
}
/*---------------------End Submit----------------------------------*/
      jQuery(document).ready(function () 
		{
			jQuery(".reportType a").hover(function () 
			{
				if(!jQuery(this).hasClass("active"))
				{
					jQuery(this).addClass("hover");
				}
			},function () 
			{
				jQuery(this).removeClass("hover");
			}
			);

			jQuery(".reportType a").click(function ()
	         {
				jQuery(".reportType a").each(function () 
				{
					jQuery(this).removeClass("hover");
					jQuery(this).removeClass("active");
				});
				if(jQuery(this).attr('id')=='common')
				{
					jQuery('#commonInfo').css('display','');
					jQuery('#expandInfo').css('display','none');
					jQuery('#manaInfo').css('display','none');
					
				}
				if(jQuery(this).attr('id')=='expand')
				{
					jQuery('#commonInfo').css('display','none');
					jQuery('#expandInfo').css('display','');
					jQuery('#manaInfo').css('display','none');
					
				}if(jQuery(this).attr('id')=='manaplace')
				{
					jQuery('#commonInfo').css('display','none');
					jQuery('#expandInfo').css('display','none');
					jQuery('#manaInfo').css('display','');
					
				}
				jQuery(this).addClass("active");
				window.scroll(0,100); 
	         }); 
		
		});	
      				
</script>


		<!-- -----------------Ket thuc Tab------------------------ -->

<!--body end -->
<?php $this->load->view('home/common/body'); ?>
<?php $this->load->view('home/common/footer'); ?>
